package homework4.com.qianfeng.dao.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import homework4.com.qianfeng.dao.IAccountDao;
import homework4.com.qianfeng.pojo.Account;

@Repository("accountDao")
public class AccountDaoImpl implements IAccountDao {

	@Autowired
	private JdbcTemplate jdbcTemplate;
	@Override
	public void update(Account account) {
		jdbcTemplate.update("update account set accountName=?, money =? where id = ?",
				account.getAccountName(), account.getMoney(), account.getId());
	}

	@Override
	public Account findAccountById(Integer id) {
		Account account = null;
		RowMapper<Account> rowMapper = new BeanPropertyRowMapper<Account>(Account.class);
		account = (Account) jdbcTemplate.queryForObject("select * from account where id = ?", rowMapper, id);
		return account;
	}

}
